@svizzle/utils/array-[object-object]

Methods

(static) applyTransformsSequence(pathFnPairs) → {function}

Source:
Since:
  • 0.6.0
See:

Return a function that expects an object and applies the provided sequence of transforms to the values of the correspondent paths to the input object. Note that transforms to the same path can be repeated.

Example
> obj = {
	a: {
		a1: 'a1',
		a2: {
			a21: 'a21',
			a22: '9',
		},
		a3: '3px',
		a4: '2',
	},
	b: {
		b1: 'b1',
		b2: {
			b21: 'foo',
			b22: '9',
			b23: '2',
			b24: '24px'
		},
		b3: '2',
		b4: '4px'
	},
}
> // orthogonal transforms
> transform = applyTransformsSequence([
	['a.a2.a22', _.pipe([Number, Math.sqrt])],
	['a.a3', parseInt],
	['b.b2.b24', parseInt],
	['b.b4', parseInt],
])
> transform(obj)
{
	a: {
		a1: 'a1',
		a2: {
			a21: 'a21',
			a22: 3,
		},
		a3: 3,
		a4: '2'
	},
	b: {
		b1: 'b1',
		b2: {
			b21: 'foo',
			b22: '9',
			b23: '2',
			b24: 24
		},
		b3: '2',
		b4: 4
	},
}

> // modifying modified paths
> transform = applyTransformsSequence([
	['b', _.values],
	['b.1', _.values],
])
> transform(obj)
{
	a: {
		a1: 'a1',
		a2: {
			a21: 'a21',
			a22: '9',
		},
		a3: '3px',
		a4: '2',
	},
	b: [
		'b1',
		[
			'foo',
			'9',
			'2',
			'24px',
		],
		'2',
		'4px'
	],
}

> // modifying paths multiple times
> transform = applyTransformsSequence([
	['b', _.values],
	['b.1', _.values],
	['b', _.flatten],
])
> transform(obj)
{
	a: {
		a1: 'a1',
		a2: {
			a21: 'a21',
			a22: '9',
		},
		a3: '3px',
		a4: '2',
	},
	b: [
		'b1',
		'foo',
		'9',
		'2',
		'24px',
		'2',
		'4px'
	],
}
Parameters:
Name Type Description
pathFnPairs array

pairs [path, function]

Returns:
  • Object -> Object
Type
function

(static) pluckValuesKeys(keys) → {function}

Source:
Since:
  • 0.8.0
See:

Return a function plucking the provided keys from the expected object values

Example
> let select = pluckValuesKeys(['a', 'k'])
> select({
	foo: {a: 1, b: 2, c: 3, k: 4},
	bar: {a: 5, b: 8}
})
{
	foo: {a: 1, k: 4},
	bar: {a: 5}
}
Parameters:
Name Type Description
keys array

array of keys to pluck

Returns:
  • Object -> Object
Type
function

(static) remapWith() → {function}

Source:
Since:
  • 0.13.0

Return a function expecting an object and returning an object having keys and values defined by applying the provided array of two functions to the input object keys and values.

Example
> remap = remapWith([
	key => `${key}${key}`,
	value => 3 * value,
]);
> remap({a: 1, b: 2})
{aa: 3, bb: 6}
Parameters:
Type Description
array

[keysFn, valuesFn] both being (Any -> Any)

Returns:
  • (Object -> Object)
Type
function